$(function () {
    let markid = getUrlString('markid');
    let isApp = getUrlString('isApp');
    let vip = '0';
    if (isApp === '1'){
        $('#goBack').hide();
    }else {
        $('#goBack').click(function () {
            nativeCommand("dancool://activity=fin")
        });
    }

    $('#help').click(function () {
        showModal('签到规则','1.每日签到会赠送用户普通扭蛋券，普通扭蛋券只可用来抽取免费扭蛋蛋机——“非洲小舢板”的商品。<br>' +
            '2.免费扭蛋蛋机商品属于赠品类商品，蛋酱对这类蛋机商品有最终解释权。<br>' +
            '3.普通扭蛋券只有在满足蛋酱指定的操作后（比如点击签到按钮），并且后台告知成功后生效，券数才会增加。<br>' +
            '4.月卡用户每日签到除可获得普通扭蛋券额外，连续7天签到可获得金币红包。<br>' +
            '5.任何违反用户协议的操作（包括但不限于破解，攻击服务器，篡改服务器数据等），一经查出蛋酱有权对帐号做出封号处理。','','确定');
    });
 


    $('#gotoCupDanji').click(function () {
        if (isApp === '1'|| isApp === '2'){
            window.location.href = urlView+'danji/cupDanji.html?danjiid=12945&markid='+markid+'&isApp='+isApp
        } else {
            window.location.href = 'dancool://web='+urlView+'danji/cupDanji.html?danjiid=12945'
        }
    });
    //获取用户信息
    function getUserInfo() {
        getData('post','/niu/apiv3/member_userinfo.php',{'markid':markid},function (data) {
            console.log(data);
            vip = data.data.vip;
            $('#nickName').html(data.data.nick);
            if (vip === '1'){
                $('.top').addClass('yktop')
            }
        })
    }
    getUserInfo();

    function getCard () {

        let data = {
            'markid':markid,
            'giftType':'sign',
        };
        getData('post','/niu/apiv4/niu_gift_card_type.php',data,function (data) {
            console.log(data)
        })
    }

    function signInticket() {
        let data = {
            'markid':markid,
            'way':'show',
            'giftType':'sign',
        };
        getData('post','/niu/apiv4/niu_gift_ticket_type.php',data,function (data) {
            console.log(data);
            if (data.resultcode === '0'){
                $('#renum').html(data.renum)
            } else {
                laymsg(data.msg)
            }

        })
    }
    signInticket();

    function signInList() {
        let data = {
            'markid':markid,
            'type':0,
        };
        getData('post','/niu/api/member_getsignlistv3.php',data,function (data) {
            console.log(data);
            if (data.resultcode === '0'){
                if (data.count !== null){
                    $('#count').html(data.count)
                }
                let append = '';
                $(data.data).each(function (i) {
                    if (i < 4){
                        append += '<li>' +
                            '                <div class="day">'+this.date+'</div>' ;
                            if (this.mark === '0'){
                                append += '<div><img src="../../res/img/signIn/noSignIn.png" alt=""></div>';
                            }else {
                                append += '<div><img src="../../res/img/signIn/signIn'+i+'.png" alt=""></div>';

                            }
                        append += '                <div class="prize">'+this.showinfo+'</div>' +
                            '            </li>'
                    } else {
                        append += '<li class="secondLi">' +
                            '                <div class="day">'+this.date+'</div>' ;
                        if (this.mark === '0'){
                            append += '<div><img src="../../res/img/signIn/noSignIn.png" alt=""></div>';

                        }else {
                            append += '<div><img src="../../res/img/signIn/signIn'+i+'.png" alt=""></div>';
                        }
                        append += '                <div class="prize">'+this.showinfo+'</div>' +
                            '            </li>'
                    }

                });
                $('.signInList').append(append)
            } else {
                laymsg(data.msg)
            }

        })
    }
    signInList();


    $('#signInbtn').click(function () {
        let data = {
            'markid':markid,
            'dosign':1,
            'type':0,
        };
        getData('post','/niu/api/member_dosignupv3.php',data,function (data) {
            console.log(data);
            // let count = $('#count').html();
            // let countNum = Number(count);
            if (data.resultcode === '0'){
                laymsg(data.msg);
                getCard();
                setTimeout(function () {
                    window.location.reload();
                },1000)
            } else {
                laymsg(data.msg);
            }

        })
    })
});


